var api = require('../../utils/api.js');
var app = getApp();


Page({

  /**
   * 页面的初始数据
   */
  data: {
    zf: 0,
    zj: 0,
    goods: [],
    goodtit: ''
  },

  onLoad(options) {
    this.setData({
      id: options.id
    })

    var that = this;
    api.get({
      url: 'wxapp/user/getordrbyid',
      data: {
        id: options.id
      },
      success: data => {
        console.log(data);
        that.setData({
          info: data.data,
          zj:data.data.zj,
          zf:data.data.zf,
          goodtit:data.data.goods,
          goods:data.data.good
        })
      }
    });

  },

  formSubmit(e) {
    console.log(e.detail.value)

    var that = this;
    var id = this.data.id;
    var data = e.detail.value;

    data.id = id;
    data.gid = this.data.info.gid;
    data.goods = this.data.goodtit;


    api.get({
      url: 'wxapp/user/saveorder',
      data: data,
      success: data => {
        wx.showToast({
          title: data.msg,
          icon: 'none'
        })

        if (data.code == 1) {
          setTimeout(function () {
            wx.reLaunch({
              url: '/pages/order/index',
            })
          }, 1500)
        }
      }
    });

  },


  bindPickerChange(ret) {
    console.log(ret);
    var index = ret.detail.value;
    var goods = this.data.goods;

    this.setData({
      index: ret.detail.value,
      goodtit: goods[index]
    })


  },



  radioChangezj(ret) {
    console.log(ret);
    this.setData({
      zj: ret.detail.value
    })
  }

})